package com.kaily.timemanager.data.presenter;

import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import com.kaily.timemanager.data.DataListener;
import com.kaily.timemanager.data.contract.TaskContract;
import com.kaily.timemanager.data.model.TaskModelImpl;
import com.kaily.timemanager.obj.Task;
import com.kaily.timemanager.obj.TaskClass;

import java.util.List;

/**
 * Created by zhoulikai on 2017/02/28
 */

public class TaskPresenterImpl implements TaskContract.Presenter {

    private TaskContract.Model model;
    private TaskContract.View view;
    private Context context;

    public TaskPresenterImpl(Context context, TaskContract.View view) {
        model = new TaskModelImpl();
        this.view = view;
        this.context = context;
    }

    @Override
    public void getAllTask(final Context context) {

        if (context != null && this.view != null && this.model != null) {
            this.model.getAllTask(context, new DataListener<List<TaskClass>>() {

                @Override
                public void onSuccess(List<TaskClass> model) {
                    view.setAllTask(model);
                }

                @Override
                public void onFailure(String msg) {
                    if (TextUtils.isEmpty(msg)) {
                        msg = "获取失败";
                    }
                    Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onFinish() {

                }
            });

        }

    }

    @Override
    public void operationTaskClass(Context context, final TaskClass taskClass, final TaskOp taskClassOp) {
        if (context != null && this.view != null && this.model != null) {
            this.model.operationTaskClass(context, taskClass, taskClassOp, new DataListener<Integer>() {

                @Override
                public void onSuccess(Integer model) {
                    view.notificationTaskClass(taskClassOp, taskClass);
                }

                @Override
                public void onFailure(String msg) {

                }

                @Override
                public void onFinish() {

                }
            });
        }


    }

    @Override
    public void operationTask(Context context, Task task, TaskOp taskClassOp) {

    }
}